<!--
 * @Description: 新建抽奖活动
 * @Author: liyujie
 * @Date: 2021/02/07
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/02/18
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <!-- title -->
            <div class="header">
                {{ type === 'add' ? '新建活动' : type === 'edit' ? '编辑活动' : '查看活动' }}
            </div>
            <!-- /header -->
            <div class="form-wrapper">
                <el-form
                    :model="ruleForm"
                    :rules="rules"
                    ref="ruleForm"
                    label-width="110px"
                    class="el-form-wrap"
                >
                    <div class="form-title">
                        基本信息
                    </div>
                    <el-form-item
                        label="活动名称"
                        prop="title"
                    >
                        <el-input
                            v-model="ruleForm.title"
                            placeholder="请输入活动名称"
                            maxlength="20"
                            show-word-limit
                            size="medium"
                            :style="{width: '400px'}"
                            :disabled="type === 'detail'"
                        />
                        <span class="form-tips">
                            建议描述具体活动，如：元宵节抽奖活动
                        </span>
                    </el-form-item>
                    <el-form-item
                        label="活动有效期"
                        prop="start_time"
                    >
                        <el-date-picker
                            v-model="dateTimeRange"
                            size="medium"
                            type="datetimerange"
                            value-format="timestamp"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :default-time="['00:00:00', '23:59:59']"
                            :disabled="type === 'detail' || status === 2"
                        />
                    </el-form-item>
                    <el-form-item
                        label="领奖截止时间"
                        prop="exchange_expire_time"
                    >
                        <el-date-picker
                            v-model="ruleForm.exchange_expire_time"
                            placeholder="选择领奖截止时间"
                            type="datetime"
                            size="medium"
                            align="center"
                            value-format="timestamp"
                            default-time="23:59:59"
                            :style="{width: '400px'}"
                            :disabled="type === 'detail'"
                        />
                    </el-form-item>
                    <div
                        class="form-title"
                        style="margin-top: 40px"
                    >
                        活动设置
                    </div>
                    <div class="tips-view">
                        1.新注册用户说明：尚未在平台下单购买商品，二、在平台下单购买过商品但是之后申请退款或者退款退货，订单列表没有完成的订单，三、在平台只购买过0元购商品的也属于新注册用户；<br>
                        2. 抽奖条件规则说明：<br>
                        （1） 单笔支付金额：用户单笔实付金额满足单笔支付金额，即可获得一次抽奖机会，如果抽奖资格上限为不限制，用户第二次下单，单笔实付金额满足单笔支付金额，可以再次获得一次抽奖机会；<br>
                        （2） 累计支付金额：用户在活动有效期内，用户单笔实付金额或多笔实付金额相加满足累计支付金额，即可获得一次抽奖机会，但是已兑换抽奖资格的多余支付金额不会累计到下一笔的实付金额，例如：活动要求累计支付金额满足69元，可获得抽奖机会，用户第一次单笔实付金额为60元，第二次单笔实付金额为40元，用户获得一次抽奖机会，用户两笔实际累计支付金额为100元，100-69=31元，多余支付金额为31元，如果用户第三次下单，单笔实付金额为60元，不会获得抽奖机会，因为已兑换抽奖资格的多余支付金额不会累计到下一笔的实付金额，系统计算当前累计支付金额为60元。<br>
                    </div>
                    <el-form-item
                        label="参与用户"
                        class="is-required"
                    >
                        <el-radio-group
                            v-model="ruleForm.student_limit_type"
                            :disabled="type === 'detail' || status === 2"
                        >
                            <el-radio
                                :label="0"
                                style="width: 100px"
                            >
                                所有用户
                            </el-radio>
                            <el-radio
                                :label="1"
                                style="width: 100px"
                            >
                                新注册用户
                            </el-radio>
                            <el-radio
                                :label="2"
                                style="width: 100px"
                            >
                                一卡通会员用户
                            </el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item
                        label="抽奖条件"
                        class="is-required"
                    >
                        <el-radio-group
                            v-model="ruleForm.chance_get_type"
                            :disabled="type === 'detail' || status === 2"
                        >
                            <el-radio
                                :label="1"
                                style="width: 100px"
                            >
                                单笔支付金额
                            </el-radio>
                            <el-radio
                                :label="2"
                                style="width: 100px"
                            >
                                累计支付金额
                                <span class="form-tips">在活动期间内的累计支付金额</span>
                            </el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item prop="chance_get_type_require">
                        <span style="color: #606266">支付金额满</span>
                        <el-input
                            v-model="ruleForm.chance_get_type_require"
                            style="width: 178px;margin-left: 12px"
                            :disabled="type === 'detail' || status === 2"
                        >
                            <span slot="suffix">元</span>
                        </el-input>
                    </el-form-item>
                    <el-form-item
                        prop="chance_get_limit"
                        label="抽奖资格上限"
                    >
                        <el-input
                            v-model="ruleForm.chance_get_limit"
                            style="width: 178px;"
                            :disabled="type === 'detail' || status === 2"
                        >
                            <span slot="suffix">次</span>
                        </el-input>
                        <span class="form-tips">填写-1为不限制</span>
                    </el-form-item>
                    <el-form-item
                        label="抽奖次数"
                        class="is-required"
                    >
                        <el-radio-group
                            v-model="ruleForm.try_limit_type"
                            :disabled="type === 'detail' || status === 2"
                        >
                            <el-radio
                                v-for="item in countType"
                                :key="item.value"
                                :label="item.value"
                                style="width: 100px"
                            >
                                {{ item.label }}
                            </el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item
                        prop="try_limit"
                        v-if="ruleForm.try_limit_type"
                    >
                        <span style="color: #606266">{{ ruleForm.try_limit_type === 1 ? '一天' : '每人' }}</span>
                        <el-input
                            v-model="ruleForm.try_limit"
                            style="width: 178px;margin-left: 12px"
                            :disabled="type === 'detail' || status === 2"
                        >
                            <span slot="suffix">次</span>
                        </el-input>
                    </el-form-item>
                    <div
                        class="form-title"
                        style="margin-top: 40px"
                    >
                        奖项设置
                    </div>
                    <div class="tips-view">
                        奖项设置说明：<br>
                        1. 区块设置必须为等分，例如6等分，8等分，并且在划分的区块中，必须有一个区块类别是未中奖；<br>
                        2. 区块数量必须与转盘奖项分区数量相等，如果设置了6个区块，则转盘必须是6等分转盘图，如果设置了8个区块，则转盘必须是8等分转盘图；<br>
                        3. 抽中概率设置说明，如果需要手动设置抽中概率，必须每个区块都设置抽中概率，如果选择不填写抽中概率，则每个区块选择默认抽中概率，计算方式如下：每个奖项的中奖概率为  【奖项配置数量】/【所有奖项配置数量】；<br>
                        4. 各个区块设置的抽中概率，累加之和必须小于或等于100%，如果累加之和等于100%，则按抽奖概率进行计算。如果累加之和小于100%，则剩余的百分比，累加到未中奖的抽中概率，例如未中奖设置的抽中概率为1%，累加之和等于95%，那么剩余的5%则累加到未中奖的抽中概率，未中奖实际抽中概率为6%；<br>
                        5. 未中奖的数量设置和中奖率可以填写为0；<br>
                        6. 如果某个区块的数量设置减去已中奖数量等于0，那么该奖项已抽完，用户实际抽奖结果为未中奖。<br>
                    </div>
                    <div
                        class="form-block"
                        v-for="(item, index) in ruleForm.item_list"
                        :key="index"
                    >
                        <div class="block-view">
                            <div class="block-title">{{ `区块${index + 1}：` }}</div>
                            <el-button
                                type="text"
                                size="medium"
                                @click="deletePrize(index)"
                                :disabled="type === 'detail'"
                            >
                                删除
                            </el-button>
                        </div>
                        <el-form-item
                            label="奖品类别"
                            class="is-required"
                        >
                            <el-radio-group
                                v-model="item.type"
                                @change="item.aim_no = ''"
                                :disabled="type === 'detail'"
                            >
                                <el-radio
                                    :label="1"
                                    style="width: 100px"
                                >
                                    赠送商品
                                </el-radio>
                                <el-radio
                                    :label="2"
                                    style="width: 100px"
                                >
                                    赠送优惠券
                                </el-radio>
                                <el-radio
                                    :label="3"
                                    style="width: 100px"
                                >
                                    赠送红包
                                </el-radio>
                                <el-radio
                                    :label="0"
                                    style="width: 100px"
                                >
                                    未中奖
                                </el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <template v-if="item.type">
                            <el-form-item
                                :prop="`item_list[${index}].item_title`"
                                :rules="rules.item_title"
                                label="奖项名称"
                            >
                                <el-input
                                    v-model="item.item_title"
                                    placeholder="请输入奖项名称"
                                    maxlength="12"
                                    show-word-limit
                                    size="medium"
                                    :style="{width: '400px'}"
                                    :disabled="type === 'detail'"
                                />
                            </el-form-item>
                            <el-form-item
                                :prop="`item_list[${index}].aim_no`"
                                :rules="rules.aim_no"
                                label="奖品设置"
                                class="is-required"
                            >
                                <el-button
                                    type="primary"
                                    size="medium"
                                    style="width: 120px"
                                    v-if="item.type === 1"
                                    :disabled="type === 'detail'"
                                    @click="showSelectDialog(index, 'goods')"
                                >
                                    选择商品
                                </el-button>
                                <el-button
                                    type="primary"
                                    size="medium"
                                    style="width: 120px"
                                    v-if="item.type === 2"
                                    :disabled="type === 'detail'"
                                    @click="showSelectDialog(index, 'coupon')"
                                >
                                    选择优惠券
                                </el-button>
                                <el-button
                                    type="primary"
                                    size="medium"
                                    style="width: 120px"
                                    v-if="item.type === 3"
                                    :disabled="type === 'detail'"
                                    @click="showSelectDialog(index, 'packet')"
                                >
                                    选择红包
                                </el-button>
                            </el-form-item>
                            <el-form-item
                                v-if="item.aim_no"
                            >
                                <div class="goods-info">
                                    <div class="title">已选{{ item.type === 1 ? '商品' : item.type === 2 ? '优惠券' : '红包' }}</div>
                                    <div class="info">
                                        <div
                                            class="left"
                                            v-if="item.type === 1"
                                        >
                                            <img
                                                :src="item.goods_info.goods_cover"
                                                @click="fnShowPreview(item.goods_info.goods_cover)"
                                            >
                                        </div>
                                        <div class="right">
                                            <div
                                                class="info-title"
                                                v-if="item.type === 1"
                                            >
                                                <div class="label">商品名称：</div>
                                                <div class="value">{{ item.goods_info.goods_title }}</div>
                                            </div>
                                            <div>
                                                {{ item.type === 1 ? '商品编号' : item.type === 2 ? '优惠券编号' : '红包编号' }}： {{ item.aim_no }}
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </el-form-item>
                            <el-form-item
                                :prop="`item_list[${index}].image`"
                                :rules="rules.image"
                                label="奖品图片"
                                class="is-required"
                            >
                                <image-upload
                                    v-model="item.image"
                                    :limit="50"
                                    :type="type"
                                    tips="尺寸200*200px，大小50kb内，支持jpg、jpeg、png"
                                />
                            </el-form-item>
                            <el-form-item
                                :prop="`item_list[${index}].title`"
                                :rules="rules.prize_title"
                                label="奖品名称"
                            >
                                <el-input
                                    v-model="item.title"
                                    placeholder="请输入奖品名称"
                                    size="medium"
                                    maxlength="20"
                                    show-word-limit
                                    :style="{width: '400px'}"
                                    :disabled="type === 'detail'"
                                />
                            </el-form-item>
                        </template>
                        <el-form-item
                            :prop="`item_list[${index}].total_count`"
                            :rules="rules.total_count"
                            label="数量设置"
                        >
                            <el-input
                                v-model="item.total_count"
                                placeholder="请设置数量设置"
                                size="medium"
                                :style="{width: '400px'}"
                                :disabled="type === 'detail'"
                            />
                        </el-form-item>
                        <el-form-item
                            label="抽中概率"
                        >
                            <el-input
                                v-model="item.award_rate"
                                placeholder="请设置抽中概率"
                                size="medium"
                                :style="{width: '400px'}"
                                :disabled="type === 'detail'"
                            >
                                <span slot="suffix">%</span>
                            </el-input>
                            <span class="form-tips">抽中概率为非必填项，不填则按系统默认抽中概率</span>
                        </el-form-item>
                        <template v-if="item.type">
                            <el-form-item
                                label="已中奖数量"
                                v-if="ruleForm.status"
                            >
                                {{ item.award_count }}
                            </el-form-item>
                        </template>
                    </div>
                    <div
                        class="add-block-btn"
                        v-if="type !== 'detail'"
                        @click="addPrizeItem"
                    >
                        + 继续添加奖项
                    </div>
                </el-form>
            </div>

            <!-- button -->
            <div class="footer">
                <el-button
                    size="medium"
                    type="default"
                    :style="{width: '120px', marginBottom: '32px'}"
                    @click="handleCancel"
                >
                    取消
                </el-button>
                <el-button
                    size="medium"
                    type="default"
                    :style="{width: '120px', marginBottom: '32px', marginLeft: '32px'}"
                    v-if="ruleForm.status === 0 && type !== 'detail'"
                    @click="handleSubmit('save')"
                >
                    存为草稿
                </el-button>
                <el-button
                    size="medium"
                    type="primary"
                    :style="{width: '120px', marginBottom: '32px', marginLeft: '32px'}"
                    @click="handleNextStep"
                >
                    下一步
                </el-button>
            </div>
        </div>

        <!--商品选择弹窗-->
        <goods-select
            ref="goodsSelect"
            @change="handleSelectGoods"
        />
        <!-- 选择优惠券 -->
        <coupon-select
            ref="couponSelect"
            @emit="handleSelectCoupon"
        />
        <!-- 选择红包 -->
        <red-packet-select
            ref="redPacketSelect"
            @emit="handleSelectPacket"
        />
        <!-- 图片预览 -->
        <img-preview ref="preview"/>
    </div>
</template>

<script>
import {back} from '@/mixin/back';
import ImageUpload from "@/components/common/image-upload";
import ImgPreview from "@/components/common/img-preview";
import GoodsSelect from '@/components/goods/goods-select';
import CouponSelect from '@/components/coupon/coupon-select.vue';
import redPacketSelect from '@/components/coupon/packet-select.vue';
import { deepClone } from '@/assets/js/utils';

let prizeItem = {
    item_no: '',
    // 奖项名称
    item_title: '',
    // 奖品类型
    type: 1,
    // 奖品图片
    image: '',
    // 商品或优惠券编号
    aim_no: '',
    // 奖品名称
    title: '',
    // 数量设置
    total_count: '',
    // 抽中概率
    award_rate: '',
    award_count: 0,
    goods_info: {
        goods_title: '',
        goods_cover: ''
    }
};
const numberReg = /(?:^[1-9]([0-9]+)?(?:\.[0-9]{1,2})?$)|(?:^(?:0)$)|(?:^[0-9]\.[0-9](?:[0-9])?$)/;

export default {
    name: 'LuckDrawEdit',
    mixins: [back],
    components: {
        ImgPreview,
        ImageUpload,
        GoodsSelect,
        CouponSelect,
        redPacketSelect
    },
    data() {
        return {
            // add新建 edit编辑 detail查看详情
            type: 'add',
            // 2:进行中 不可编辑活动有效期和活动设置内容
            status: 0,
            ruleForm: {
                lottery_no: '',
                // 活动名称
                title: '',
                // 活动有效期
                start_time: '',
                end_time: '',
                // 领取截止时间
                exchange_expire_time: '',
                // 参与用户
                student_limit_type: 0,
                // 参与条件
                chance_get_type: 1,
                // 支付金额满多少元
                chance_get_type_require: '',
                // 抽奖资格上限
                chance_get_limit: '',
                // 抽奖次数类型
                try_limit_type: 1,
                // 抽奖限制次数
                try_limit: '',
                // 是否存为草稿
                only_save: 1,
                item_list: [deepClone(prizeItem), deepClone(prizeItem), deepClone(prizeItem)],
                page_config: {},
                // 状态,1:正常 0:草稿 -1:已失效
                status: 0
            },
            rules: {
                title: [
                    {required: true, message: '请填写活动名称', trigger: 'blur'}
                ],
                start_time: [
                    {required: true, message: '请选择活动有效期', trigger: 'blur'}
                ],
                exchange_expire_time: [
                    {required: true, message: '请选择领取截止时间', trigger: 'blur'}
                ],
                chance_get_type_require: [
                    {required: true, message: '请填写支付满金额', trigger: 'blur'},
                    {pattern: numberReg, message: '支付金额必须为数字', trigger: 'blur'}
                ],
                chance_get_limit: [
                    {required: true, message: '请填写抽奖次数上限', trigger: 'blur'},
                    {pattern: /^-?[0-9]\d*$/, message: '抽奖次数上限必须为整数', trigger: 'blur'}
                ],
                try_limit: [
                    {required: true, message: '请填写抽奖限制数量', trigger: 'blur'},
                    {pattern: numberReg, message: '抽奖限制数量必须为数字', trigger: 'blur'}
                ],
                item_title: [
                    {required: true, message: '请填写奖项名称', trigger: 'blur'}
                ],
                image: [
                    {required: true, message: '请上传奖品图片', trigger: 'blur'}
                ],
                aim_no: [
                    {required: true, message: '请填写商品、优惠券或红包', trigger: 'blur'}
                ],
                prize_title: [
                    {required: true, message: '请填写奖品名称', trigger: 'blur'}
                ],
                total_count: [
                    {required: true, message: '请填写数量设置', trigger: 'blur'},
                    {pattern: numberReg, message: '数量设置必须为数字', trigger: 'blur'}
                ],
            },
            editIndex: 0,
            dateTimeRange: [],
            countType: [
                {label: '按天限制', value: 1},
                {label: '不限参与次数', value: 0},
            ],
            authResult: {}
        };
    },
    mounted() {
        this.init();
    },
    watch: {
        dateTimeRange(value) {
            this.ruleForm.start_time = value ? value[0] / 1000 : '';
            this.ruleForm.end_time = value ? value[1] / 1000 : '';
        }
    },
    methods: {
        /**
         * 初始化
         */
        init() {
            let query = this.$route.query;

            this.$store.commit('SET_HEADER', [
                {title: "APP后台"}, {title: '商城'}, {title: '抽奖活动', path: '/student/luck-draw-list'},
                {title: query.type === 'add' ? '新建活动' : query.type === 'edit' ? '编辑活动' : '查看活动'}
            ]);
            this.type = query.type;
            this.status = query.status ? Number(query.status) : 0;
            this.ruleForm.lottery_no = query.no;
            this.authResult = this.$route.meta.authResult;
            if (this.type !== 'add' || query.no) {
                this.ruleForm.lottery_no = query.no;
                this.getDetailData();
            }
        },

        /**
         * 获取详情数据
         */
        getDetailData() {
            this.$post('/student/shop_tool%5Clottery%5Cget', {lottery_no: this.ruleForm.lottery_no}, resp => {
                if (resp.code === 1) {
                    let query = this.$route.query;

                    this.ruleForm = resp.data;
                    this.ruleForm.item_list.forEach(item => {
                        if(!item.goods_info) {
                            item.goods_info = {};
                        }
                    });
                    if(resp.data.start_time) {
                        this.dateTimeRange = [resp.data.start_time * 1000, resp.data.end_time * 1000];
                    }
                    this.ruleForm.exchange_expire_time = resp.data.exchange_expire_time ? resp.data.exchange_expire_time * 1000 : '';
                    if(this.type !== 'add') {
                        this.ruleForm.lottery_no = query.no;
                    }
                    if(query.isCopy) {
                        this.ruleForm.status = 0;
                    }
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * 选择商品或优惠券
         * @param index
         * @param type
         */
        showSelectDialog(index, type) {
            this.editIndex = index;
            if (type === 'goods') {
                this.$refs.goodsSelect.show(1);
            }

            if (type === 'coupon') {
                this.$refs.couponSelect.show('coupon_nos');
            }

            if (type === 'packet') {
                this.$refs.redPacketSelect.show();
            }
        },

        /**
         * 选择优惠券
         * @param val
         */
        handleSelectCoupon(val) {
            let data = val.list[0];

            this.$refs.couponSelect.close();
            this.$set(this.ruleForm.item_list[this.editIndex], 'aim_no', data.coupon_no);
        },

        /**
         * 选择红包
         * @param val
         */
        handleSelectPacket(val) {
            let data = val.list[0];

            this.$refs.redPacketSelect.close();
            this.$set(this.ruleForm.item_list[this.editIndex], 'aim_no', data.packet_no);
        },

        /**
         * 获取选择的商品
         * @param val
         */
        handleSelectGoods(val) {
            this.$set(this.ruleForm.item_list[this.editIndex], 'aim_no', val.goods_no);
            this.$set(this.ruleForm.item_list[this.editIndex].goods_info, 'goods_title', val.goods_title);
            this.$set(this.ruleForm.item_list[this.editIndex].goods_info, 'goods_cover', val.goods_cover);
        },

        /**
         * 添加奖项
         */
        addPrizeItem() {
            if(this.ruleForm.item_list.length >= 12) {
                this.$message.warning('最多可以添加12条奖项');
                return;
            }
            this.ruleForm.item_list.push(deepClone(prizeItem));
        },

        /**
         * 删除奖项
         * @param index
         */
        deletePrize(index) {
            if(this.ruleForm.item_list.length <= 3) {
                this.$message.warning('最少需保留3条奖项');
                return;
            }
            this.ruleForm.item_list.splice(index, 1);
        },

        /**
         * 预览图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         * @param index
         */
        fnShowPreview(images, index) {
            if (images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images, index);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 下一步
         */
        handleNextStep() {
            // 查看详情直接跳转
            if(this.type === 'detail') {
                let query = this.$route.query;

                this.handleRoute('luckDrawConfig', {no: query.no, type: query.type, status: query.status});
            } else {
                this.$refs['ruleForm'].validate((valid) => {
                    if(valid) {
                        this.handleSubmit('next');
                    }
                });
            }

        },

        /**
         * 保存
         * @param type save存草稿 next下一步
         */
        handleSubmit(type) {
            let query = this.$route.query;
            let params = JSON.parse(JSON.stringify(this.ruleForm));
            let rate_all = 0;

            params.exchange_expire_time = params.exchange_expire_time / 1000;
            params.item_list.forEach(item => {
                if(item.award_rate !== '') {
                    rate_all += Number(item.award_rate);
                } else {
                    item.award_rate = -1;
                }
            });
            if(rate_all > 100) {
                this.$message.warning('抽中概率总和不能大于100%');
                return;
            }
            params.only_save = params.status === 0 ? 1 : 0;
            params.item_list = JSON.stringify(params.item_list);
            params.page_config = JSON.stringify(params.page_config);
            if(!query.isCopy) {
                params.lottery_no = query.no;
            }

            this.$post('/student/shop_tool%5Clottery%5Csave', params, resp => {
                if (resp.code === 1) {
                    if(type === 'next') {
                        let query = this.$route.query;

                        this.handleRoute('luckDrawConfig', {no: resp.data.lottery_no, type: query.type, status: query.status});
                    }
                    if(type === 'save') {
                        this.$notify({
                            title: '提示',
                            message: '保存成功',
                            type: 'success',
                            duration: 2000
                        });
                        this.handleRoute('luckDrawList');
                    }
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * @description 返回
         */
        handleCancel() {
            if (this.type === 'detail') {
                this.handleRoute('luckDrawList');
            } else {
                this.$confirm('返回后将不会保存您所修改的内容,是否返回', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.handleRoute('luckDrawList');
                });
            }
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;
    overflow-y: auto;
    &::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }

    .content-wrapper {
        display: flex;
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;
        overflow: auto;

        /*header*/

        .header {
            width: 100%;
            height: 68px;
            display: flex;
            align-items: center;
            white-space: nowrap;
            box-sizing: border-box;
            padding-left: 35px;
            color: rgba(51, 51, 51, 1);
            font-size: 20px;
            font-weight: 500;
            position: relative;
            border-bottom: 1px rgba(233, 233, 233, 1) solid;

            &::before {
                content: '';
                background: rgba(24, 144, 255, 1);
                width: 3px;
                height: 20px;
                position: absolute;
                top: 23px;
                left: 25px;
            }
        }

        // 表单
        .form-wrapper {
            background: #FBFBFB;
            border: 1px solid #EEEEEE;
            padding: 20px 32px;
            margin: 24px;

            .form-title {
                font-size: 16px;
                font-family: PingFangSC-Semibold, PingFang SC;
                font-weight: 600;
                color: #333333;
                border-bottom: 1px solid #E9E9E9;
                padding: 12px 0;
                margin-bottom: 24px;
            }

            .form-tips {
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #999999;
                margin-left: 12px;
            }
            .tips-view {
                display: flex;
                align-items: center;
                padding: 12px 24px;
                margin-bottom: 12px;
                min-height: 42px;
                background: #FFF6D6;
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #896C43;
                line-height: 22px;
            }
            .block-view {
                height: 58px;
                background: #F0F0F0;
                border-radius: 2px;
                border-bottom: 1px solid #DCDFE6;
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding: 0 30px;
                margin-bottom: 24px;
                .block-title {
                    font-size: 16px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #333333;
                }
            }
            .form-block {
                background: #F7F7F7;
                border-radius: 2px;
                border: 1px solid #DCDFE6;
                padding-bottom: 24px;
                margin-bottom: 32px;
            }

            .add-block-btn {
                height: 36px;
                line-height: 36px;
                text-align: center;
                color: #20A0FF;
                cursor: pointer;
                background: #FFFFFF;
                border-radius: 4px;
                border: 1px solid #20A0FF;
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
            }
            .goods-info {
                width: 538px;
                background: #FFFFFF;
                border-radius: 4px;
                border: 1px solid #DCDFE6;
                display: flex;
                flex-direction: column;
                .title {
                    height: 42px;
                    line-height: 42px;
                    border-bottom: 1px solid #DCDFE6;
                    padding: 0 24px;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #333;
                }
                .info {
                    flex: 1;
                    display: flex;
                    padding: 15px 24px;
                    .left {
                        img {
                            width: 84px;
                            cursor: pointer;
                            margin-right: 16px;
                        }
                    }
                    .right {
                        max-height: 84px;
                        display: flex;
                        flex-direction: column;
                        justify-content: space-between;
                        font-size: 14px;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #333333;
                        line-height: 20px;
                        .info-title {
                            display: flex;
                            .label {
                                width: 74px;
                                flex-shrink: 0;
                            }
                            .value {
                                height: 40px;
                                overflow : hidden;
                                text-overflow: ellipsis;
                                display: -webkit-box;
                                -webkit-line-clamp: 2;
                                -webkit-box-orient: vertical;
                            }
                        }
                    }
                }
            }
        }

        .footer {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 8px;
        }

        /deep/ .el-form {
            .is-required {
                .el-form-item__label {
                    &:before {
                        content: "*";
                        display: inline-block;
                        color: #F56C6C;
                        margin-right: 4px;
                    }
                }
            }
        }
    }

    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow: 0 1px 0 0 rgba(233, 233, 233, 1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;

        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }

        .el-icon-close:before {
            color: rgb(194, 194, 194);
            font-size: 17px;
            font-weight: bold;
        }

        .el-dialog__headerbtn {
            top: 14px;
        }
    }

    /deep/ .el-textarea__inner {
        resize: none;
    }

    /deep/ .el-input__suffix {
        margin-right: 6px;
    }
}
</style>
